home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6069 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: leeds.ac.uk!news
  3. From: csyamc@scs.leeds.ac.uk (A M Casey)
  4. Subject: changing strings via pointers
  5. Message-ID: <1996Feb22.125436.25503@leeds.ac.uk>
  6. NNTP-Posting-Host: csgi23.leeds.ac.uk
  7. Organization: The University of Leeds, School of Computer Studies
  8. Date: Thu, 22 Feb 1996 12:54:35 +0000 (GMT)
  9.  
  10. I reading in strings from a file using fgets, which stores the "\n" in
  11. the array of chars which I have declared using a pointer.
  12.  
  13. The thing is, I want to get rid of the "\n" and replace it with "\0", but
  14. obviously I can only do this using the pointer. I'm using the following code:
  15.  
  16. char *Contents < pointer to string
  17.  
  18. int count = 0;
  19.  
  20.  
  21. while (*(Contents + count)!= NULL)  /* the end of string is not reached */
  22. {if (*(Contents + count) == atoi("\n"))
  23. /* change the \n to a \0 and set the next char along to null */
  24. {
  25. *(Contents + count) = atoi("\0");
  26.  
  27. *(Contents + count + 1) = NULL;
  28.  
  29.  
  30. else
  31. /* read in the next char */
  32. {
  33. count++;
  34.  
  35. I think the problem maybe my way of using the pointer - I can print out each
  36. char as I get to it, but it doesnt seem to change the array at all.
  37. Should I be using atoi?, it doesnt seem to work without it.
  38.  
  39. Cheers
  40.  
  41. ANdy
  42.  
  43.  
  44.  
  45.  
  46.